<template>
  <div id="main" ref="echartRef"></div>
</template>

<script setup lang="ts">
import * as echarts from 'echarts';

// const props = defineProps<{
//   optionData: {}[]
// }>()
const props = defineProps(['optionData'])
let echartRef = ref()

watch(() => props['optionData'], (newValue, oldValue) => {
  let dataList = newValue['data'].map((item: { value: any, name: any }) => ({ value: item.value, name: item.name }));
  let myChart = echarts.init(echartRef.value as HTMLElement)
  let option = {
    tooltip: {
      trigger: 'item'
    },
    color:newValue['color'],
    legend: {
      orient: 'vertical',
      left: 'right'
    },
    series: [
      {
        name: 'Access From',
        type: 'pie',
        radius: '50%',
        label:{
          show: false
        },
        data: dataList,
        emphasis: {
          itemStyle: {
            shadowBlur: 10,
            shadowOffsetX: 0,
            shadowColor: 'rgba(0, 0, 0, 0.5)'
          }
        }
      }
    ]
  };
  option && myChart.setOption(option)
})
onMounted(() => {

})

</script>

<style lang="scss" scoped></style>
